package com.cqc.gdmap02;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RideRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkRouteResult;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private MapView mapView;
    private AMap map;
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Button btn6;
    private Button btn7;
    private Button btn8;
    private Button btn9;
    private Button btn10;
    private UiSettings uiSet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);

        if (map == null) {
            map = mapView.getMap();
        }
        uiSet = map.getUiSettings();

        //未完成
//        initRouteSearch();

        findViews();
        initViews();

    }

    private void initRouteSearch() {
        RouteSearch search = new RouteSearch(this);
//        RouteSearch.FromAndTo fat = new RouteSearch.FromAndTo("","");
//        RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery()
        search.setRouteSearchListener(routeSearchListener);
    }

    private RouteSearch.OnRouteSearchListener routeSearchListener = new RouteSearch.OnRouteSearchListener() {
        @Override
        public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {

        }

        @Override
        public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int i) {

        }

        @Override
        public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {

        }

        @Override
        public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) {

        }
    };

    private void initViews() {
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
        btn6.setOnClickListener(this);
        btn7.setOnClickListener(this);
        btn8.setOnClickListener(this);
        btn9.setOnClickListener(this);
        btn10.setOnClickListener(this);
    }

    private void findViews() {
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);
        btn6 = (Button) findViewById(R.id.btn6);
        btn7 = (Button) findViewById(R.id.btn7);
        btn8 = (Button) findViewById(R.id.btn8);
        btn9 = (Button) findViewById(R.id.btn9);
        btn10 = (Button) findViewById(R.id.btn10);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                map.setMapType(AMap.MAP_TYPE_NORMAL);
                break;
            case R.id.btn2:
                map.setMapType(AMap.MAP_TYPE_SATELLITE);
                break;
            case R.id.btn3:
                map.setMapType(AMap.MAP_TYPE_NIGHT);
                break;
            case R.id.btn4:
                map.showIndoorMap(true);
                break;
            case R.id.btn5:
                if (map.isTrafficEnabled()) {
                    map.setTrafficEnabled(false);
                } else {
                    map.setTrafficEnabled(true);
                }
                break;
            case R.id.btn6:
                if (uiSet.isZoomControlsEnabled()) {
                    uiSet.setZoomControlsEnabled(false);
                } else {
                    uiSet.setZoomControlsEnabled(true);
                }
                break;
            case R.id.btn7:
                if (uiSet.isCompassEnabled()) {
                    uiSet.setCompassEnabled(false);
                } else {
                    uiSet.setCompassEnabled(true);
                }
                break;
            case R.id.btn8:
                if (uiSet.isScaleControlsEnabled()) {
                    uiSet.setScaleControlsEnabled(false);
                } else {
                    uiSet.setScaleControlsEnabled(true);
                }
                break;
            case R.id.btn9:
                uiSet.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);
                break;
            case R.id.btn10:

                break;
        }
    }
}
